package com.enjoyor.soa.traffic.rest.tsms.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.RltRouteDeviceDto;
import com.enjoyor.soa.traffic.api.dto.tsms.RltRoutePostDto;
import com.enjoyor.soa.traffic.api.dto.tsms.TaskInfoDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.IRltRouteDeviceConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/rltDevice" })
@Api("RltRouteDeviceController相关api")
@CrossOrigin
public class RltRouteDeviceController {

	@Autowired
	private IRltRouteDeviceConsumeService iRltRouteDeviceConsumeService;

	/**
	 * 获取关联设备分页；
	 * 
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@GetMapping(value = { "/getRltRouteDevicePage" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation(value = "关联设备分页", notes = "关联设备分页")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rltDeviceId", value = "设备关联编号", paramType = "query", dataType = "string"),
	        @ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", dataType = "string"),
			@ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "string"),
			@ApiImplicitParam(name = "deviceId", value = "设备编号", paramType = "query", dataType = "string"),
			@ApiImplicitParam(name = "deviceName", value = "设备名称", paramType = "query", dataType = "string"),
			@ApiImplicitParam(name = "deviceTypeId", value = "设备类型编号", paramType = "query", dataType = "string") })
	public ResultPojo getRltRouteDevicePage(
			@RequestParam(defaultValue = "") String rltDeviceId,
			@RequestParam(defaultValue = "") String taskId, 
			@RequestParam(defaultValue = "") String routeId, 
			@RequestParam(defaultValue = "") String deviceId,
			@RequestParam(defaultValue = "") String deviceName, 
			@RequestParam(defaultValue = "") String deviceTypeId,
			Page page, HttpServletRequest request) {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo = iRltRouteDeviceConsumeService.getRltRouteDevicePage(page, rltDeviceId, taskId, routeId, deviceId,
				deviceName, deviceTypeId);
		return resultPojo;
	}

	/**
	 * 获取关联设备list；
	 * 
	 * @return
	 */
	@GetMapping(value = { "/getRltDeviceList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = RltRouteDeviceDto.class, code = 0, message = "")
	@ApiOperation("关联设备List查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rltDeviceId", value = "设备关联编号", paramType = "query", dataType = "string"),
	        @ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", dataType = "string"),
			@ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "string"),
			@ApiImplicitParam(name = "deviceId", value = "设备编号", paramType = "query", dataType = "string"),
			@ApiImplicitParam(name = "deviceName", value = "设备名称", paramType = "query", dataType = "string"),
			@ApiImplicitParam(name = "deviceTypeId", value = "设备类型编号", paramType = "query", dataType = "string") })
	public ResultPojo getRltDeviceList(
			@RequestParam(defaultValue = "") String rltDeviceId,
			@RequestParam(defaultValue = "") String taskId, 
			@RequestParam(defaultValue = "") String routeId, 
			@RequestParam(defaultValue = "") String deviceId,
			@RequestParam(defaultValue = "") String deviceName, 
			@RequestParam(defaultValue = "") String deviceTypeId,
			HttpServletRequest request) {
		return iRltRouteDeviceConsumeService.getRltRouteDeviceList(rltDeviceId, taskId, routeId, deviceId, deviceName,
				deviceTypeId);
	}

	/**
	 * 添加关联设备；
	 * 
	 * @return
	 */
	@PostMapping(value = { "/addRltRouteDevice" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加设备关联信息(单条)")
	public ResultPojo addRltRouteDevice(@RequestBody RltRouteDeviceDto rltRouteDeviceDto, HttpServletRequest request) {
		return iRltRouteDeviceConsumeService.insertRltRouteDevice(rltRouteDeviceDto,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}

	/**
	 * 修改关联信息；
	 * 
	 * @return
	 */
	@PutMapping(value = { "/editRltRouteDevice" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改关联设备信息(单条)")
	public ResultPojo editRltRouteDevice(@RequestBody RltRouteDeviceDto rltRouteDeviceDto, HttpServletRequest request) {
		return iRltRouteDeviceConsumeService.editRltRouteDevice(rltRouteDeviceDto,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}

	/**
	 * 删除关联设备信息；
	 * 
	 * @return
	 */
	@DeleteMapping(value = { "/delRltRouteDevice" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("删除关联设备信息(单条)")
	@ApiImplicitParam(name = "rltDeviceId", value = "rltDeviceId", paramType = "query", required = true, dataType = "String")
	public ResultPojo delRltRouteDevice(
			@RequestParam(defaultValue = "",value="rltDeviceId", required=true) String rltDeviceId,
			HttpServletRequest request) {
		return iRltRouteDeviceConsumeService.deleteRltRouteDevice(rltDeviceId,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}

	/**
	 * 线路关联设备
	 * 
	 * @return zyh
	 */
	@PostMapping(value = { "/rltRouteDeviceList" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("线路关联设备")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "deviceTypeId", value = "设备类型编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "rltDeviceList", value = "关联设备信息", paramType = "body", dataType = "List<RltRouteDeviceDto>")})
	public ResultPojo rltRouteDeviceList(
			@RequestParam(defaultValue = "", value="taskId", required=true) String taskId,
			@RequestParam(defaultValue = "", value="routeId", required=false) String routeId,
			@RequestParam(defaultValue = "", value="deviceTypeId", required=false) String deviceTypeId,
			@RequestBody List<RltRouteDeviceDto> rltDeviceList, HttpServletRequest request) {
		return iRltRouteDeviceConsumeService.rltRouteDeviceList(rltDeviceList, taskId, routeId, deviceTypeId,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}

	/**
	 * 替换线路中的关联设备
	 * @return zyh
	 */
	@PostMapping(value = { "/replaceRouteDevice" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("替换线路中的关联设备")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "rltDeviceId", value = "关联设备编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "rltRouteDeviceDto", value = "替换设备信息", paramType = "body", dataType = "RltRouteDeviceDto")})
	public ResultPojo replaceRouteDevice(
			@RequestParam(defaultValue = "", value="rltDeviceId", required=true) String rltDeviceId, 
			@RequestBody RltRouteDeviceDto rltRouteDeviceDto,
			HttpServletRequest request) {
		return iRltRouteDeviceConsumeService.replaceRouteDevice(rltRouteDeviceDto, rltDeviceId,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
}
